//
//  MainJoyMatchViewController.m
//  JoyfulFurnishing
//
//  Created by 李书勋 on 14/12/17.
//  Copyright (c) 2014年 apple. All rights reserved.
//

#import "MainJoyMatchViewController.h"
#import "NetHandle.h"
#import "ScreenViewController.h"
#import "TurnPhotoCell.h"

@interface MainJoyMatchViewController ()<UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, retain)NSString *destStyle;
@property (nonatomic, retain)UITableView *tableView;
@end

@implementation MainJoyMatchViewController
-(instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.destStyle = @"任意空间";
    }
    return self;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    //http://api.guju.com.cn/v2/photo/flownew?start=0&count=5&user=(null)&cate=0&style=0&color=0
    //[self handleData];
    
    // 设置导航栏颜色
    self.navigationController.navigationBar.barTintColor = [UIColor orangeColor];
    // 设置导航栏 标题
    self.navigationItem.title = @"首页";
    
    
    //添加 导航栏 的左右按钮
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"搭配" style:UIBarButtonItemStylePlain target:self action:@selector(leftBarButtonClicked:)];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"筛选" style:UIBarButtonItemStylePlain target:self action:@selector(rightBarButtonClicked:)];
    
   
    self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.view addSubview:self.tableView];
    [_tableView release];
    
    
    
    
    
    
    
}
- (void)dealloc
{
    [_destStyle release];
    [_tableView release];
    [super dealloc];
}
- (void)rightBarButtonClicked:(UIBarButtonItem *)item
{
    ScreenViewController *screenVC = [[ScreenViewController alloc] init];
    [self.navigationController pushViewController:screenVC animated:YES];
    [screenVC setChangeName:^(NSString *str) {
        self.destStyle = str;
    }];
    [screenVC release];
}

- (void)leftBarButtonClicked:(UIBarButtonItem *)item
{
    NSLog(@"%@", item.title);
    if ([item.title isEqualToString:@"搭配"]) {
        item.title = @"单品";
    }else{
        item.title = @"搭配";
    }
    //
    

}

- (void)handleData
{
    NSString *path = @"http://api.guju.com.cn/v2/photo/flownew?start=0&count=5&user=(null)&cate=0&style=0&color=0";
    
    [NetHandle getDataWithURL:path completion:^(NSData *data) {
        NSError *error = nil;
        NSDictionary *result = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&error];
        NSLog(@"%@", result);
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 100;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0) {
        TurnPhotoCell *cell = [tableView dequeueReusableCellWithIdentifier:@"turnPhoto"];
        if (cell  == nil) {
            cell = [[[TurnPhotoCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"turnPhoto"] autorelease];
        }
        return cell;
        
    }else{
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"hahaha"];
        if (cell == nil) {
            cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"hahaha"] autorelease];
        }
        
        cell.textLabel.text = @"haoshi";
        return cell;
        
    }
    
}




/*
#pragma mark - Navigation

 
 
 
 
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
